package com.aitsuki.plugin

import javassist.ClassPool
import javassist.CtClass

/**
 * Created by hp on 2016/4/7.
 */
public class Inject {

    public static void injectClass(String path,String libPath) {

        ClassPool classes = ClassPool.getDefault()
        classes.appendClassPath(path)
        classes.appendClassPath(libPath)
        CtClass c = classes.getCtClass("com.meng.ioc_demo.MainActivity")
        if (c.isFrozen()) {
            c.defrost()
        }

        def constructor = c.getConstructors()[0];
        constructor.insertAfter("System.out.println(com.meng.hack.Hack.class);")
        c.writeFile(path)

        c = classes.getCtClass("com.meng.ioc_demo.WelcomeAty")
        if (c.isFrozen()) {
            c.defrost()
        }

        constructor = c.getConstructors()[0];
        constructor.insertAfter("System.out.println(com.meng.hack.Hack.class);")
        c.writeFile(path)

    }
}
